home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 June / PersonalComputerWorld-June2009-CoverdiscCD.iso / Software / Freeware / Adobe AIR 1.5.1 / AdobeAIRInstaller.exe / setup.swf / scripts / mx / binding / Watcher.as < prev   
Encoding:
Text File  |  2009-02-12  |  4.1 KB  |  170 lines

  1. package mx.binding
  2. {
  3.    import mx.collections.errors.ItemPendingError;
  4.    import mx.core.mx_internal;
  5.    
  6.    use namespace mx_internal;
  7.    
  8.    public class Watcher
  9.    {
  10.       mx_internal static const VERSION:String = "3.0.0.0";
  11.       
  12.       protected var children:Array;
  13.       
  14.       public var value:Object;
  15.       
  16.       protected var cloneIndex:int;
  17.       
  18.       protected var listeners:Array;
  19.       
  20.       public function Watcher(param1:Array = null)
  21.       {
  22.          super();
  23.          this.listeners = param1;
  24.       }
  25.       
  26.       public function removeChildren(param1:int) : void
  27.       {
  28.          children.splice(param1);
  29.       }
  30.       
  31.       public function updateChildren() : void
  32.       {
  33.          var _loc1_:int = 0;
  34.          var _loc2_:int = 0;
  35.          if(children)
  36.          {
  37.             _loc1_ = int(children.length);
  38.             _loc2_ = 0;
  39.             while(_loc2_ < _loc1_)
  40.             {
  41.                children[_loc2_].updateParent(this);
  42.                _loc2_++;
  43.             }
  44.          }
  45.       }
  46.       
  47.       protected function shallowClone() : Watcher
  48.       {
  49.          return new Watcher();
  50.       }
  51.       
  52.       protected function wrapUpdate(param1:Function) : void
  53.       {
  54.          var wrappedFunction:Function = param1;
  55.          try
  56.          {
  57.             wrappedFunction.apply(this);
  58.          }
  59.          catch(itemPendingError:ItemPendingError)
  60.          {
  61.             value = null;
  62.          }
  63.          catch(rangeError:RangeError)
  64.          {
  65.             value = null;
  66.          }
  67.          catch(error:Error)
  68.          {
  69.             if(error.errorID != 1006 && error.errorID != 1009 && error.errorID != 1010 && error.errorID != 1055 && error.errorID != 1069)
  70.             {
  71.                throw error;
  72.             }
  73.          }
  74.       }
  75.       
  76.       private function valueChanged(param1:Object) : Boolean
  77.       {
  78.          if(param1 == null && value == null)
  79.          {
  80.             return false;
  81.          }
  82.          var _loc2_:* = typeof value;
  83.          if(_loc2_ == "string")
  84.          {
  85.             if(param1 == null && value == "")
  86.             {
  87.                return false;
  88.             }
  89.             return param1 != value;
  90.          }
  91.          if(_loc2_ == "number")
  92.          {
  93.             if(param1 == null && value == 0)
  94.             {
  95.                return false;
  96.             }
  97.             return param1 != value;
  98.          }
  99.          if(_loc2_ == "boolean")
  100.          {
  101.             if(param1 == null && value == false)
  102.             {
  103.                return false;
  104.             }
  105.             return param1 != value;
  106.          }
  107.          return true;
  108.       }
  109.       
  110.       public function notifyListeners(param1:Boolean) : void
  111.       {
  112.          var _loc2_:int = 0;
  113.          var _loc3_:int = 0;
  114.          if(listeners)
  115.          {
  116.             _loc2_ = int(listeners.length);
  117.             _loc3_ = 0;
  118.             while(_loc3_ < _loc2_)
  119.             {
  120.                listeners[_loc3_].watcherFired(param1,cloneIndex);
  121.                _loc3_++;
  122.             }
  123.          }
  124.       }
  125.       
  126.       protected function deepClone(param1:int) : Watcher
  127.       {
  128.          var _loc3_:int = 0;
  129.          var _loc4_:int = 0;
  130.          var _loc5_:Watcher = null;
  131.          var _loc2_:Watcher = shallowClone();
  132.          _loc2_.cloneIndex = param1;
  133.          if(listeners)
  134.          {
  135.             _loc2_.listeners = listeners.concat();
  136.          }
  137.          if(children)
  138.          {
  139.             _loc3_ = int(children.length);
  140.             _loc4_ = 0;
  141.             while(_loc4_ < _loc3_)
  142.             {
  143.                _loc5_ = children[_loc4_].deepClone(param1);
  144.                _loc2_.addChild(_loc5_);
  145.                _loc4_++;
  146.             }
  147.          }
  148.          return _loc2_;
  149.       }
  150.       
  151.       public function updateParent(param1:Object) : void
  152.       {
  153.       }
  154.       
  155.       public function addChild(param1:Watcher) : void
  156.       {
  157.          if(!children)
  158.          {
  159.             children = [param1];
  160.          }
  161.          else
  162.          {
  163.             children.push(param1);
  164.          }
  165.          param1.updateParent(this);
  166.       }
  167.    }
  168. }
  169.  
  170.